<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/WEB-INF/jsp/commons/taglibs.jsp" %>

<!-- content -->
<form id="inputForm" class="well form-inline" action="${ctx}/point/rule/save" method="post">
    <input type="hidden" name="id" id="ruleId" value="${pointRule.id}"/>
    <table class="table table-striped table-bordered table-condensed">
        <thead>
        <strong>
            <i class="icon-flag"></i>
            积分兑换规则表单
        </strong>
        </thead>
        <tr>
            <td class="span2">编号:</td>
            <td>
                <input id="code" readonly="readonly" name="code" type="text" value="${pointRule.code}" size="30"
                       maxlength="80"/>
            </td>
        </tr>
        <tr>
            <td class="span2">积分码:</td>
            <td>
                <input type="text" name="iCode" id="iCode" value="${pointRule.iCode}"/>
            </td>
        </tr>
        <tr>
            <td>积分规则:</td>
            <td>
                <input id="point" name="point" type="text" value="${pointRule.point}" class="span1" maxlength="80"/>
                <span class="tBlue">正数增加积分，负数扣减积分</span>
            </td>
        </tr>

        <tr>
            <td>操作员:</td>
            <td>
                <input id="oper" name="oper" type="text" value="${USER.name}" readonly="readonly"/>
            </td>
        </tr>

        <tr>
            <td>备注:</td>
            <td>
                <textarea id="memo" name="memo" rows="4" class="span6">${pointRule.memo}</textarea>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <input class="btn" type="submit" value="提交"/>
                &nbsp;
                <input class="btn" type="button" value="返回" back="back"/>
            </td>
        </tr>
    </table>
</form>


<script>
    $(document).ready(function () {

        // 邮政编码验证
        jQuery.validator.addMethod("veryfyCode", function (value, element) {
            var tel = /^[0-9A-Za-z]+$/;
            return this.optional(element) || (tel.test(value));
        }, "积分码只能为数字和字母");

        //聚焦第一个输入框
        $("#name").focus();
        //为inputForm注册validate函数
        $("#inputForm").validate({
            rules: {
                code: "required",
                point: {
                    number: true,
                    required: true
                },
                iCode: {
                    required: true,
                    veryfyCode: true,
                    remote: {
                        url: "${ctx}/point/rule/repeat",     //后台处理程序
                        type: "post",               //数据发送方式
                        dataType: "json",           //接受数据格式
                        data: {                     //要传递的数据
                            iCode: function () {
                                return $("#iCode").val();
                            },
                            ruleId: function () {
                                return $("#ruleId").val();
                            }
                        }
                    }
                }
            },

            messages: {
                iCode: {
                    remote: "积分码重复，请重新输入！"
                }
            }

        });

        if (!$("#code").val()) {

            var _date = new Date();
            var _code = "N" + _date.getTime();
            $("#code").val(_code);
        }
    });
</script>